import { Component, OnInit,Injector } from '@angular/core';
import {UserService} from "../../services/user.service";
@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.css']
})
export class HeaderComponent implements OnInit {
  _user:UserService;
  constructor(private injector:Injector) {
    //从注入器中获取UserService 实例
    //这和在构造函数注入服务是一样的
    this._user=this.injector.get(UserService);

  }
  ngOnInit() {
    console.log(this._user.getuser())
  }

}
